package com.irdstudio.bsp.console.service.impl;

import java.util.*;

import com.irdstudio.bsp.console.dao.domain.SAgentInfo;
import com.irdstudio.bsp.console.service.vo.HomePageVO;
import com.irdstudio.bsp.console.service.vo.SSubsInfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.sdk.beans.core.base.FrameworkService;
import com.irdstudio.bsp.console.dao.HomePageDao;
import com.irdstudio.bsp.console.dao.domain.HomePage;
import com.irdstudio.bsp.console.service.facade.HomePageService;

@Service("PageService")
public class HomePageServiceImpl implements HomePageService, FrameworkService {
	
    private static Logger logger = LoggerFactory.getLogger(HomePageServiceImpl.class);
    
    @Autowired
    private HomePageDao homePageDao;
    
	/** 特殊业务系统编码-控制台 */
	private final String CONSOLE_CODE = "console";


    @Override
    public List<HomePageVO> queryAll(List<String> list) {
        logger.debug("当前查询参数信息为:"+list.toString());
        List<HomePageVO> homePageVOList =null;
        List<HomePage> homePages=new LinkedList<>();
        try{
            if (list!=null){
                for (String subsCode:list) {
                    HomePage homePage = homePageDao.queryAll(subsCode);//根据传入的数组查询
                    homePages.add(homePage);
                }
                logger.debug("当前查询本人所属数据信息的结果集数量为:"+ homePages.size());
                homePageVOList = (List<HomePageVO>) beansCopy(homePages,HomePageVO.class);
                System.out.println(homePageVOList);
            }
        }catch (Exception e){
            logger.error("数据转换出现异常!", e);
        }
        return homePageVOList;
    }

    /**
     * dmp-console首页信息查询实现类
     * @param list
     * @return
     */
    @Override
    public List<Map> querydmpconsoleAll(List<SSubsInfoVO> list) {
        logger.debug("当前查询参数信息为:"+list.toString());
        List<Map> resultmap=new ArrayList<>();
        try{
          if(list.size()==0){
            return   resultmap;
          }
            for (SSubsInfoVO item:list) {
                if(!CONSOLE_CODE.equals(item.getSubsCode())) {
                    Map map=new HashMap();
                    String subsName = item.getSubsName();
                    String subsCode = item.getSubsCode();//拿到系统编号查询数据
                    map.put("subsCode",subsCode);//业务系统代码
                    map.put("subsName",subsName);//业务系统名称
                    Map<String, Object> params=new HashMap();
                    params.put("subsCode",subsCode);
                    params.put("tableName","migrate_table_info");
                    params.put("opttype","1");
                    Integer source_table = homePageDao.querysourcetablecount(params);
                    map.put("source_table",source_table);//源表个数
                    params.put("opttype","3");
                    Integer centre_table = homePageDao.querysourcetablecount(params);
                    map.put("centre_table",centre_table);//中间表个数
                    params.put("opttype","2");
                    Integer target_table = homePageDao.querysourcetablecount(params);
                    map.put("target_table",target_table);//目标表个数
                    params.remove("opttype");
                    params.put("tableName","migrate_check_rule");
                    Integer migrate_check_rule = homePageDao.querysourcetablecount(params);
                    map.put("migrate_check_rule",migrate_check_rule);//校验规则
                    params.put("tableName","migrate_check_index");
                    Integer migrate_check_index = homePageDao.querysourcetablecount(params);
                    map.put("migrate_check_index",migrate_check_index);//校验指标
                    params.put("tableName","bat_batch_info_config");
                    Integer bat_batch_info_config = homePageDao.querysourcetablecount(params);
                    map.put("bat_batch_info_config",bat_batch_info_config);//批次迁移
                    params.put("tableName","migrate_govern_task");
                    Integer migrate_govern_task =  homePageDao.querysourcetablecount(params);
                    map.put("migrate_govern_task",migrate_govern_task);//治理任务
                    resultmap.add(map);
                }
            }
        }catch (Exception e){
            logger.error("数据转换出现异常!", e);
        }
        return resultmap;
    }
}
